package com.ruoyi.web.controller.productManagement;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.StoreCookingMethods;
import com.ruoyi.system.service.IStoreCookingMethodsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 门店做法，用于存储商品附加做法的信息及加价规则Controller
 *
 * @author ruoyi
 * @date 2025-05-26
 */
@Api(tags="门店做法")
@RestController
@RequestMapping("/system/storeCookingMethods")
public class StoreCookingMethodsController extends BaseController
{
    @Autowired
    private IStoreCookingMethodsService storeCookingMethodsService;

    /**
     * 查询门店做法列表
     */
    @ApiOperation("查询门店做法列表")
    @PreAuthorize("@ss.hasPermi('system:methods:list')")
    @GetMapping("/list")
    public TableDataInfo list(StoreCookingMethods storeCookingMethods)
    {
        startPage();
        List<StoreCookingMethods> list = storeCookingMethodsService.selectStoreCookingMethodsList(storeCookingMethods);
        return getDataTable(list);
    }

    /**
     * 导出门店做法列表
     */
    @ApiOperation("导出门店做法列表")
    @PreAuthorize("@ss.hasPermi('system:methods:export')")
    @Log(title = "门店做法", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StoreCookingMethods storeCookingMethods)
    {
        List<StoreCookingMethods> list = storeCookingMethodsService.selectStoreCookingMethodsList(storeCookingMethods);
        ExcelUtil<StoreCookingMethods> util = new ExcelUtil<StoreCookingMethods>(StoreCookingMethods.class);
        util.exportExcel(response, list, "门店做法数据");
    }

    /**
     * 通过id获取门店做法详细信息
     */
    @ApiOperation("通过id获取门店做法详细信息")
    @PreAuthorize("@ss.hasPermi('system:methods:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(storeCookingMethodsService.selectStoreCookingMethodsById(id));
    }

    /**
     * 新增门店做法
     */
    @ApiOperation("新增门店做法")
    @PreAuthorize("@ss.hasPermi('system:methods:add')")
    @Log(title = "门店做法", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StoreCookingMethods storeCookingMethods)
    {
        return toAjax(storeCookingMethodsService.insertStoreCookingMethods(storeCookingMethods));
    }

    /**
     * 修改门店做法
     */
    @ApiOperation("修改门店做法")
    @PreAuthorize("@ss.hasPermi('system:methods:edit')")
    @Log(title = "门店做法", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StoreCookingMethods storeCookingMethods)
    {
        return toAjax(storeCookingMethodsService.updateStoreCookingMethods(storeCookingMethods));
    }

    /**
     * 通过id批量删除门店做法信息
     */
    @ApiOperation("通过id批量删除门店做法信息")
    @PreAuthorize("@ss.hasPermi('system:methods:remove')")
    @Log(title = "门店做法", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(storeCookingMethodsService.deleteStoreCookingMethodsByIds(ids));
    }
}
